//
//  UIImage+Extension.swift
//  Sina
//
//  Created by 朱玉龙 on 16/10/8.
//  Copyright © 2016年 朱玉龙. All rights reserved.
//

import UIKit

extension UIImage {
    
    
    func compressImage(width: CGFloat) -> UIImage {
        
        if width > self.size.width {
            return self
        }
        
        let height  = self.size.height / self.size.width * width
        
        UIGraphicsBeginImageContextWithOptions(CGSize(width: width, height: height), false
            , UIScreen.main.scale)
        self.draw(in: CGRect(x: 0, y: 0, width: width, height: height))
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image!
    }
    
    
}
